<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="门头" prop="signboard">
        <el-input
          v-model="queryParams.signboard"
          placeholder="请输入门头"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户信息" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入账户信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人银行卡" prop="card">
        <el-input
          v-model="queryParams.card"
          placeholder="请输入法人银行卡"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务区域" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入服务区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照" prop="license">
        <el-input
          v-model="queryParams.license"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['api/business:partner:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['api/business:partner:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['api/business:partner:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['api/business:partner:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="partnerList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="门头" align="center" prop="signboard" />
      <el-table-column label="账户信息" align="center" prop="account" />
      <el-table-column label="法人银行卡" align="center" prop="card" />
      <el-table-column label="服务区域" align="center" prop="area" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column
        label="营业执照"
        align="center"
        prop="license"
        width="100"
      >
        <template slot-scope="scope">
          <image-preview :src="scope.row.license" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          {{
            scope.row.status == "0"
              ? "待审核"
              : scope.row.status == "1"
              ? "审核通过"
              : "审核不通过"
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['api/business:partner:edit']"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业合伙人对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="门头" prop="signboard">
          {{ form.signboard }}
        </el-form-item>
        <el-form-item label="账户信息" prop="account">
          {{ form.account }}
        </el-form-item>
        <el-form-item label="法人银行卡" prop="card">
          {{ form.card }}
        </el-form-item>
        <el-form-item label="服务区域" prop="area">
          {{ form.area }}
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          {{ form.phone }}
        </el-form-item>
        <el-form-item label="营业执照" prop="license">
          <image-preview :src="form.idCardBack" :width="240" :height="150" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">审核通过</el-button>
        <el-button type="danger" @click="refuseForm">拒绝申请</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPartner,
  getPartner,
  delPartner,
  addPartner,
  updatePartner,
  agreePartner,
  refusePartner,
} from "@/api/api/business/partner";

export default {
  name: "Partner",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业合伙人表格数据
      partnerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        signboard: null,
        account: null,
        card: null,
        area: null,
        phone: null,
        license: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "状态不能为空", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业合伙人列表 */
    getList() {
      this.loading = true;
      listPartner(this.queryParams).then((response) => {
        this.partnerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        signboard: null,
        account: null,
        card: null,
        area: null,
        phone: null,
        license: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业合伙人";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPartner(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业合伙人";
      });
    },
    /** 提交按钮 */
    submitForm() {
      agreePartner(this.form.id).then((response) => {
        this.$modal.msgSuccess("审核通过");
        this.open = false;
        this.getList();
      });
    },
    refuseForm() {
      refusePartner(this.form.id).then((response) => {
        this.$modal.msgSuccess("审核通过");
        this.open = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除企业合伙人编号为"' + ids + '"的数据项？')
        .then(function () {
          return delPartner(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "api/business/partner/export",
        {
          ...this.queryParams,
        },
        `partner_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
